<#macro paginate currentPage totalPage actionUrl="" pageParam="p">
    <#if (totalPage <= 0) || (currentPage > totalPage)><#return></#if>

    <#-- 处理分页链接与参数 - start -->
    <#if !actionUrl?? || actionUrl?length lt 1>
        <#local requestURI = (request.requestUri)!"">
        <#local queryString = (request.queryString)!"">
        <#if queryString?? && queryString?length gt 0>
            <#local queryString = queryString?replace("&"+pageParam+"="+currentPage+"&", "&")>
            <#local queryString = queryString?replace("&"+pageParam+"="+currentPage, "")>
            <#local queryString = queryString?replace(pageParam+"="+currentPage+"&", "")>
            <#local queryString = queryString?replace(pageParam+"="+currentPage, "")>
        </#if>
        <#if queryString?? && queryString?length gt 0>
            <#local actionUrl = requestURI + "?" + queryString + "&" + pageParam + "=">
        <#else>
            <#local actionUrl = requestURI + "?" + pageParam + "=">
        </#if>
    </#if>
    <#-- 处理分页链接与参数 - end -->

    <#local startPage = currentPage - 4>
    <#if (startPage < 1)><#local startPage = 1></#if>

    <#local endPage = currentPage + 4>
    <#if (endPage > totalPage)><#local endPage = totalPage></#if>

   <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
    <#if (currentPage <= 8)>
    <#local startPage = 1>
    </#if>
    <#if ((totalPage - currentPage) < 8)>
    <#local endPage = totalPage>
    </#if>

    <#if (currentPage == 1)>
        <a class="paginate_button previous disabled">上一页</a>
    <#else>
        <a class="paginate_button previous" href="${actionUrl}#{currentPage - 1}">上一页</a>
    </#if>

    <#if (currentPage > 8)>
        <a class="paginate_button" href="${actionUrl}#{1}">#{1}</a>
        <a class="paginate_button" href="${actionUrl}#{2}">#{2}</a>
        <a href="${actionUrl}#{3}">...</a>
    </#if>

    <#list startPage..endPage as i>
        <#if currentPage == i>
          <span>
          <a class="paginate_button current" aria-controls="DataTables_Table_0" data-dt-idx="#{i}" tabindex="0">#{i}</a>
          </span>
        <#else>
            <a class="paginate_button" href="${actionUrl}#{i}">#{i}</a>
        </#if>
    </#list>

    <#if ((totalPage - currentPage) >= 8)>
        <a href="${actionUrl}#{totalPage - 2}">...</a>
        <a class="paginate_button" href="${actionUrl}#{totalPage - 1}" >#{totalPage - 1}</a>
        <a class="paginate_button" href="${actionUrl}#{totalPage}">#{totalPage}</a>
    </#if>

    <#if (currentPage == totalPage)>
       <a class="paginate_button previous disabled">下一页</a>
    <#else>
         <a class="paginate_button previous" href="${actionUrl}#{currentPage + 1}">下一页</a>
    </#if>
    </div>
    
</#macro>
